package org.hismig.utils;

import java.io.File;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class CheckTool {

	public static void checkFileExist(String fileName) {
		checkNotEmpty(fileName);

		File file = new File(fileName);
		
		System.out.println(file.getAbsolutePath());
		System.out.println(file.exists());
		checkNotNull(file);
		checkArgument(file.exists());
		file = null;
	}

	public static void checkNotEmpty(String str) {
		checkNotNull(str);
		checkArgument(!str.isEmpty());
	}

	/**
	 * check the obj,if null then thown a NullPointException
	 * 
	 * @param obj
	 */
	public static void checkNotNull(Object obj) {
		if (null == obj) {
			throw new NullPointerException();
		}
	}

	/**
	 * check the argument expression,if wrong then thown an
	 * IllegalArgumentException
	 * 
	 * @param expression
	 */
	public static void checkArgument(boolean expression) {
		if (!expression) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * check the state expression,if wrong then thown an IllegalStateException
	 * 
	 * @param expression
	 */
	public static void checkState(boolean expression) {
		if (!expression) {
			throw new IllegalStateException();
		}
	}
}
